AWOL:
See reply #4
Ok so i think i converted the numbers into int. But why is it that this statement is not satisfied?
if (dataNumber >= 50 )
{
digitalWrite(relay, HIGH);
}
else
{
digitalWrite(relay, LOW);
}
delay(3000);
Here's my full code:
// Example 4 - Receive a number as text and convert it to an int
#include <SoftwareSerial.h>
SoftwareSerial XBee(10, 11); // RX, TX
#define relay 5
int relayPin = 4; // Pin of Relay Module
const byte numChars = 32;
char receivedChars[numChars]; // an array to store the received data
boolean newData = false;
int dataNumber = 0; // new for this version
void setup() {
XBee.begin(9600);
Serial.begin(9600);
Serial.println("<Arduino is ready>");
pinMode(relay, OUTPUT);
digitalWrite(relayPin, HIGH);
}
void loop() {
recvWithEndMarker();
showNewNumber();
}
void recvWithEndMarker() {
static byte ndx = 0;
char endMarker = '\n';
char rc;
if (XBee.available() > 0) {
rc = XBee.read();
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
receivedChars[ndx] = '\0'; // terminate the string
ndx = 0;
newData = true;
}
}
}
void showNewNumber() {
if (newData == true) {
dataNumber = 0; // new for this version
dataNumber = atoi(receivedChars); // new for this version
Serial.print("This just in ... ");
Serial.println(receivedChars);
Serial.print("Data as Number ... "); // new for this version
Serial.println(dataNumber); // new for this version
newData = false;
}
}
void runningtheRelay() {
if (dataNumber >= 50 )
{
digitalWrite(relay, HIGH);
}
else
{
digitalWrite(relay, LOW);
}
delay(3000);
}
thanks!