Pages: [1]   Go Down
Author Topic: X-bee + Arduino prope - need proper buffer-less flow  (Read 385 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 82
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ola everyone!

Was just trying out something crazy and thought of showing carbon monoxide levels as pencil plots (Something like carbon rings on paper) by controlling the translation of a servo attached to a Arduino over  wireless x-bee network (See pic below for "Receiver plotter.png").
A MQ7 equipped with an LCD and X-bee on an Arduino will act as the sensor transmitter(Made it successfully and is working. See Pic below-"Transmitter sensor.png") .

The Anaglog voltages are well printed on the LCD(As indicative CO levels) and show the same data on X-CTU's terminal over wireless X-bee network.
(with a "." in fornt of each received data like . 123, .234 etc etc).

this is the Transmitter sensor code:
Code:
[/font][/size]

#include <LiquidCrystal.h>

int sensorValue;

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup()
{
  Serial.begin(9600);
  lcd.begin(16, 2); 
}

void loop()
{
sensorPrintFunction();
}

void sensorPrintFunction()
{
  sensorValue = analogRead(0);       // read analog input pin 0
  Serial.println(sensorValue, DEC);  // prints the value read
  delay(100);                        // wait 100ms for next reading
 
  lcd.clear(); // Clear the display
  lcd.print("CO level:"); // Print some text
  lcd.setCursor(0,1);
  lcd.print(sensorValue);
  delay(200);
}

I'm receiving values ranging from 120-400(depending on environment I'm in currently).

The only concern is, the servo's not translating as fast with the data change and it even does not change at all sometimes in cases like when the value changes from say 164 - 175. I could just hear a noise from the servo and that's it. I'm using 9gms micro servos but tried with bigger ones also.
I need a noticeable and rapid  translations in the servo.

Here's the receiver end's code:

Code:
#include <Servo.h>

Servo myservo;
int x = 0;

void setup()
{
  Serial.begin(9600);
  myservo.attach(9);
}

void loop()
{
 
  while(Serial.available())
  {
    x = Serial.read()-'0';
    Serial.flush();
  }
  myservo.write(x);
  delay(5);
 
 }

Please Help me with the code.

What i'm guessing is may be
 1. Buffer problem-But I'm using "Serial.flush();"
 2. May be delay can have some effect. Not effected much I tried. (Have to try few more shots.)
 3. using "volatile byte" as datatype for the incoming serial data did not make much difference too. (Did not tried it sincerely though) .

Help me here anybody.


* transmitter sensor_bb.png (241.02 KB, 3399x1665 - viewed 6 times.)
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 82
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Forgot to attach the receiver plotter schematic
. Please look for the attachments




* receiver plotter_bb.png (139.9 KB, 1398x1014 - viewed 5 times.)
Logged

Pages: [1]   Go Up
Jump to: