Newbie needs help



  • Hi,

    I just started on mysensors and I have zero knowledge in electronics.

    I want to create some sensor nodes using arduino pro mini.

    However i have few doubts. Hope someone can help a newbie.

    1. I can see only one VCC pin (excluding the one on programming header which i would like keep it for uploading sketches in future). How do I connect my radio and sensor? Shouldn't it be at least 2 VCC pins? Or can I fit in 2 wires into the same VCC pin?

    2. I'm powering the sensor node with 2 AA batteries. The negative terminal goes to ground. What about the positive terminal? Does is goes to RAW?

    I'm sorry for the silly questions.


  • Mod

    Welcome @masterkenobi !

    1: You can connect as many things as you like to the vcc pin. A breakout board is very handy when prototyping to make it easy to connect many things to the same pin.

    2: it depends. Search for 2xAA in the forum and you'll find lots of discussions. But to get started connect + on the batteries to Vcc.



  • @mfalkvidd thanks.

    I manage to build a couple of sensors powered by 2 AA batteries.

    However I'm stuck at monitoring the battery level.

    After I uploaded BatteryPoweredSensor.ino to my board, it overwrote the sensor sketch I uploaded earlier.

    Do I have to merge both sketches into one before upload?


  • Hero Member

    Yes each time you upload a sketch it replaces the one that is already there.



  • Here you have a sample of one of my battery nodes. Now I'm using V2.0 of Library, but this used to work before updating

    #include <MySensor.h>  
    #include <SPI.h>
    #include <BH1750.h>
    
    #define SN "SensorLuz"
    #define SV "1.0"
    unsigned long SLEEP_TIME = 300000; // 5 minutos
    #define CHILD_ID_LIGHT 0
    #define NODE_ID 7
    
    #define VBAT_PER_BITS 0.003363075  
    #define VMIN 1.9                                  //  Vmin (radio Min Volt)=1.9V (564v)
    #define VMAX 3.0                                  //  Vmax = (2xAA bat)=3.0V (892v)
    int batteryPcnt = 0;                              // Calc value for battery %
    int batLoop = 0;                                  // Loop to help calc average
    int BATTERY_SENSE_PIN = A0; 
    
    MySensor gw;
    BH1750 lightSensor;
    
    uint16_t lastlux;
    
    MyMessage msgLux(CHILD_ID_LIGHT, V_LEVEL);
    MyMessage msgLuxUnit(CHILD_ID_LIGHT, V_UNIT_PREFIX);
    
    void setup()  
    {  
       analogReference(INTERNAL);
    
      gw.begin(NULL, NODE_ID);
      lightSensor.begin();
      gw.sendSketchInfo(SN, SV);
      gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
      gw.send(msgLuxUnit.set("lux"));
    
    }
    
    void loop()     
    {     
    
      uint16_t lux = lightSensor.readLightLevel();
      Serial.print("Lux: ");
      Serial.println(lux);
      if (lux != lastlux) {
          gw.send(msgLux.set(lux));
          lastlux = lux;
      }
      batM();
      
      gw.sleep(SLEEP_TIME);
    }
    
    void batM() //The battery calculations
    {
       delay(500);
       int sensorValue = analogRead(BATTERY_SENSE_PIN);    
       delay(500);
       
       float Vbat  = sensorValue * VBAT_PER_BITS;
       int batteryPcnt = static_cast<int>(((Vbat-VMIN)/(VMAX-VMIN))*100.);
       //Serial.print("Battery percent: "); Serial.print(batteryPcnt); Serial.println(" %");  
       
      
       if (batLoop > 24) {  //24 ciclos de 5 min = 2h.
         gw.sendBatteryLevel(batteryPcnt);
         batLoop = 0;
       }
       else 
       {
       batLoop++;
       }
    }
    


  • @Boots33 said:

    Yes each time you upload a sketch it replaces the one that is already there.

    Thanks.

    @danivalencia said:

    Here you have a sample of one of my battery nodes. Now I'm using V2.0 of Library, but this used to work before updating

    Thanks.

    There is also another thing concern me. What if my neighbor also into Mysensors? Will he be able to view all the data from my sensors? How do I secure the nodes?



  • @masterkenobi said:

    There is also another thing concern me. What if my neighbor also into Mysensors? Will he be able to view all the data from my sensors? How do I secure the nodes?

    Take a look at https://forum.mysensors.org/topic/1021/security-introducing-signing-support-to-mysensors


Log in to reply
 

Suggested Topics

10
Online

11.4k
Users

11.1k
Topics

112.7k
Posts