analogRead only works in Arduino IDE[solved]
-
Arduino Nano, Arduino IDE 1.6.8.
I am reading 4 analog inputs, everything works fine when I have the Node powered to my PC and running AIDE with Monitor opened , if I close the Monitor it goes into a special mode waiting for programming(this is normal) but when I power the Node from the wall(USB) it doesn't send Child data. I see the Node is registering in Domoticz but no Child data.If i remove the delay(5000) or gw.wait(5000), just before sending Child data, it doesn't work in Arduino IDE either, very strange for me.
#include <MySensor.h> #include <SPI.h> #define CHILD_ID_MQ2 0 #define CHILD_ID_MQ3 1 #define CHILD_ID_MQ7 2 #define CHILD_ID_MQ135 3 unsigned long SLEEP_TIME = 60000; const int MQ2 = A0; //GAS sensor output pin to Arduino analog A0 pin const int MQ3 = A1; //GAS sensor output pin to Arduino analog A0 pin const int MQ7 = A2; //GAS sensor output pin to Arduino analog A0 pin const int MQ135 = A3; //GAS sensor output pin to Arduino analog A0 pin int mq2; int mq3; int mq7; int mq135; MySensor gw; MyMessage MQ2Msg(CHILD_ID_MQ2, V_LEVEL); MyMessage MQ3Msg(CHILD_ID_MQ3, V_LEVEL); MyMessage MQ7Msg(CHILD_ID_MQ7, V_LEVEL); MyMessage MQ135Msg(CHILD_ID_MQ135, V_LEVEL); void setup() { gw.begin(); gw.sendSketchInfo("Multi MQ Sensors", "1.0"); gw.present(CHILD_ID_MQ2, S_AIR_QUALITY); gw.present(CHILD_ID_MQ3, S_AIR_QUALITY); gw.present(CHILD_ID_MQ7, S_AIR_QUALITY); gw.present(CHILD_ID_MQ135, S_AIR_QUALITY); Serial.begin(115200); //Initialize serial port - 9600 bps } void loop() { mq2 = analogRead(MQ2); //gw.wait(5000); mq3 = analogRead(MQ3); //gw.wait(5000); mq7 = analogRead(MQ7); //gw.wait(5000); mq135 = analogRead(MQ135); delay(5000); gw.send(MQ2Msg.set(mq2)); gw.send(MQ3Msg.set(mq3)); gw.send(MQ7Msg.set(mq7)); gw.send(MQ135Msg.set(mq135)); gw.sleep(SLEEP_TIME); }I had some other strange errors, sometimes when I rebooted I could send to GW.
After I changed the Nano to Pro Mini it works all the time and every where. I think I got a damaged Nano, even if it was working perfect for month as another Node.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login