element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Autodesk EAGLE
  • Products
  • More
Autodesk EAGLE
EAGLE User Support (English) wire communication between 2 arduinos
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Autodesk EAGLE to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Not Answered
  • Replies 3 replies
  • Subscribers 180 subscribers
  • Views 413 views
  • Users 0 members are here
Related

wire communication between 2 arduinos

Former Member
Former Member over 10 years ago

i am having issues getting my code to display the reading from the sensors on the lcd which is located on the second arduino

this is the code that i wrote for it and any help would be great in getting it to work.

 

//reciever

#include <SPI.h>

#include <LiquidCrystal.h>

int heartratepin=A1;

int inpin=A0;

LiquidCrystal lcd(30,31,32,33,34,35);

void setup()

{

  lcd.begin(16,2);

  Serial.begin(9600);

}

void loop()

{

  if(Serial.available()==1)

  {

    int inByte=Serial.read();

    int analogValue=analogRead(inpin);

    lcd.print(analogValue);

    lcd.print(",");

   

    int newHeartReading=analogRead(heartratepin);

    lcd.print(newHeartReading);

    lcd.print(",");

   

   

 

 

  }

}

 

 

//sender

int inpin=A0;

int TEMP=0;

int heartratepin=A1;

int difference;

int newHeartReading = 0;

int lastHeartReading = 0;

int measurements[5] = {0,0,0,0,0};

int historySize = 5;

int recenttotal = 0;

int Index = 0;

boolean highChange = false;

int minimumdifference = 2;

int num[5];

int average=0;

 

 

// Heart rate timing

long lastHeartbeatTime = 0;

long debounceDelay = 150;       // the debounce time; increase if the output flickers

int currentHeartrate = 0;

int lastHeartrate = 0;

//Heart rate LED

int ledState = LOW;

long ledOnMillis = 0;

long ledOnInterval = 50;

int slope = ((newHeartReading-lastHeartReading)/(debounceDelay-lastHeartrate));

 

 

 

 

 

 

// Debugging string

String debugOutput = "";

void setup() {

   // start serial port at 9600 bps:

   Serial.begin(9600);

   // pinMode(heartratepin,INPUT);

   establishContact();

}

void establishContact() {

while (Serial.available() <= 0) {

      Serial.println("hello");   // send a starting message

      delay(300);

   }

}

void loop() {

 

   int analogValue = analogRead(inpin);

   float millivolts = (analogValue/1024.0)*5000;

   float celsius = millivolts/10-50;

   Serial.println(analogValue);

   Serial.print(celsius);

   Serial.print("c");

   Serial.print((celsius*9)/5+32);

   Serial.print("F");

   newHeartReading = analogRead(heartratepin);

    //calculation

  difference = newHeartReading - lastHeartReading;

  lastHeartReading = newHeartReading;

 

  // Find new recent total

  recenttotal = recenttotal - measurements[Index] + difference;

  // replace indexed recent value

  measurements[Index] = difference;

   //index + 1 index = (index + 1) % historySize;

    for (int i=0; i<5; i=i+1){

               num[i]=0;        

   }

    

              if (Index>=5)

              Index=0;

              //calculating the average

              average=recenttotal/5;

              Serial.println(average);

              delay(10);

  if (recenttotal >= minimumdifference)

  {

    // possible heart rate check timing

    if (millis() - lastHeartbeatTime >= debounceDelay)   // whatever the reading is at, it's been there for longer

    // than the debounce delay, so take it as the actual current state:

 

 

    {

  // Heart rate

  //digitalWrite(ledPin, HIGH);

  currentHeartrate = 60000 / (millis() - lastHeartbeatTime);

    lastHeartbeatTime = millis();

   Serial.println(newHeartReading);

      if (currentHeartrate <= 200)// && currentHeartrate > 20)

    { 

                 

                  Serial.print("Heart Rate =" + String(currentHeartrate) + "  ");

                  delay(10);

    }

            if (currentHeartrate <= 39 and currentHeartrate >= 0){

                

                  Serial.print("I Am Sick");

                }

                 delay(10);

          if (currentHeartrate<= 79 and currentHeartrate >= 70){

                

                  Serial.print("Night Mare");

                }

                delay(10);

            if (currentHeartrate <= 69 and currentHeartrate >= 40){

               

                  Serial.print("kid Is At Sleep");

          }

              delay(10);

              if (currentHeartrate <= 99 and currentHeartrate >= 80){

                 

                  Serial.print("Kid Is Resting");

             }

                delay(10);

                if (currentHeartrate <= 119 and currentHeartrate >= 100){

                

                  Serial.print("Kid Is Playing");

               }

             

                  if(currentHeartrate > 120){

                   

                    Serial.print(" The Kid Is Having ");

                 

                    Serial.print(" A Heart Attack");

                }

  

  

 

 

   // print different formats:

   Serial.write(analogValue);  // Print the raw binary value

   Serial.print('\t');             // print a tab

   Serial.write(newHeartReading);  // Print the raw binary value

  Serial.print('\t');             // print a tab

 

}

  }

}

  • Sign in to reply
  • Cancel
Parents
  • gadget.iom
    0 gadget.iom over 10 years ago

    In your receiver code you have the following line:

    int inByte=Serial.read();

    which is taking the input characters from the serial string. The issue is that you don't appear to be using "inByte" anywhere else in that code.

    You appear to reading and displaying analog values locally on the receiver instead.

     

    Try replacing all of the LCD print institutions with a single line:

    lcd.print(inByte);

     

     

    Your new code on the receiver should be something like:

    // Reciever
    #include <SPI.h>
    #include <LiquidCrystal.h>
    LiquidCrystal lcd(30,31,32,33,34,35);
    void setup() {
      lcd.begin(16,2);
      Serial.begin(9600);
    }
    void loop() {
      if(Serial.available()==1) {
        int inByte=Serial.read();
        lcd.print(inByte);
      }
    }

     

    See how you get on with that.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • gadget.iom
    0 gadget.iom over 10 years ago

    In your receiver code you have the following line:

    int inByte=Serial.read();

    which is taking the input characters from the serial string. The issue is that you don't appear to be using "inByte" anywhere else in that code.

    You appear to reading and displaying analog values locally on the receiver instead.

     

    Try replacing all of the LCD print institutions with a single line:

    lcd.print(inByte);

     

     

    Your new code on the receiver should be something like:

    // Reciever
    #include <SPI.h>
    #include <LiquidCrystal.h>
    LiquidCrystal lcd(30,31,32,33,34,35);
    void setup() {
      lcd.begin(16,2);
      Serial.begin(9600);
    }
    void loop() {
      if(Serial.available()==1) {
        int inByte=Serial.read();
        lcd.print(inByte);
      }
    }

     

    See how you get on with that.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
  • Former Member
    0 Former Member over 10 years ago in reply to gadget.iom

    it didnt work

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube