Transmitter and Receiver program

Hi all,

Its been two weeks since I start using Arduino for my final year project.

My final year project is to develop a program for bedsore showing the temperature, pressure, sound buzzer, LCD display, transistor and receiver. I have to show the same display on the transistor display with the receiver display.

Right now I am stuck with the transistor and receiver program. Currently my program is able to display the temperature tmp36, fsr pressure sensor , sound buzzer when it meet the threshold and LCD display.

This is my radiometrix TX2-433-160-5V and RX2-433-160-5V.

Currently this is my program:

/***************************************
Libraries
***************************************/

#include <LiquidCrystal.h>

#include "pitches.h"
// notes in the melody:

int melody[] = {NOTE_B4, NOTE_B4, NOTE_FS5, NOTE_FS5, NOTE_GS5
, NOTE_GS5, NOTE_FS5, NOTE_NONE, NOTE_E5, NOTE_E5, NOTE_DS5, NOTE_DS5, NOTE_CS5
, NOTE_CS5, NOTE_B4, NOTE_NONE, NOTE_FS5, NOTE_FS5, NOTE_E5, NOTE_E5, NOTE_DS5, NOTE_DS5, NOTE_CS5
, NOTE_NONE, NOTE_FS5, NOTE_FS5, NOTE_E5, NOTE_E5, NOTE_DS5, NOTE_DS5
, NOTE_DS5, NOTE_DS5, NOTE_CS5, NOTE_NONE, NOTE_B4, NOTE_B4, NOTE_FS5, NOTE_FS5
, NOTE_GS5, NOTE_GS5, NOTE_FS5, NOTE_NONE, NOTE_E5, NOTE_E5, NOTE_DS5, NOTE_DS5, NOTE_CS5, NOTE_CS5, NOTE_B4, NOTE_NONE};

int noteDurations[] = {
  2,2,2,2,2,2,2
 ,2
 ,2,2,2,2,2,2,2
 ,2
 ,2,2,2,2,2,2,2
 ,2
 ,2,2,2,2,4,4,4,4,2
 ,2
 ,2,2,2,2,2,2,2
 ,2
 ,2,2,2,2,2,2,2
 ,2
 };

/***************************************
  Connections
***************************************/

int force_nor = 0;
int alarm = 0;

int buzzer_pin = 6;
int temp_pin = A0;
int fsr_pin = A3;

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

/***************************************
  Declarations
***************************************/

int threshold_force = 0;
int forceCondition; 
int i = 0;
int temperature; 
float force; 

/***************************************
  Arduino Setup and Loop
***************************************/

void setup() 
{
 lcd.begin(16, 2);
 lcd.clear();
 Serial.begin(9600);
 pinMode(buzzer_pin, OUTPUT);
}

void loop()
{
 temperature = getTemperature(temp_pin);

 force = analogRead(fsr_pin);

 force_nor=map(force,695,0,0,99);

 Serial.print("force:\t"); 
 Serial.println(force);

 forceCondition = 80;
  if (force > forceCondition)
  {
   threshold_force = 1;
  }
 else
   {
     threshold_force = 0;
   }
 
 lcd.clear();
 lcd.setCursor(0, 0);
  
 lcd.setCursor(0, 0);
 lcd.print("Pres:");
 lcd.setCursor(5, 0);
 lcd.print((int)force); //A3

 lcd.setCursor(9, 1);
 lcd.print("Temp:");
 lcd.setCursor(14, 1);
 lcd.print((int)temperature);

 if ((threshold_force == 1))
   {
     alarm =1;
     playSong();
   }
     else
     {
       alarm=0;
     }
   
 delay(500);
}

/***************************************
  Twinkle Star
***************************************/

//twinkle twinkle little star

char notes[] = "ccggaag ffeeddc ggffeed ggffeed ccggaag ffeeddc "; // a space represents a rest
int beats[] = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 };
int tempo = 300;

void playTone(int tone, int duration) 
 {
   for (long i = 0; i < duration * 1000L; i += tone * 2) 
   {
     digitalWrite(buzzer_pin, HIGH);
     delayMicroseconds(tone);
     digitalWrite(buzzer_pin, LOW);
     delayMicroseconds(tone);
   }
 }

/***************************************
  Sensor Management
***************************************/

void makeSong(int pin, int frequency, int duration) 
{
 tone(pin, frequency);
 delay(duration);
 tone(pin, frequency);
 delay(duration);
 noTone(pin);
} 
float getTemperatureVoltage(int pin) 
 {
   return (float)(analogRead(pin) / 1024.0) * 5.0;
 }

int getTemperature(int pin) 
 {
   return (getTemperatureVoltage(temp_pin) - 0.5) * 100;
 }

void temperatureAlert(int pin) 
 {
   makeSong(pin, 5000, 200);
 }

void forceAlert(int pin) 
 {
   makeSong(pin, 3000, 100);
 }

void playSong()
{  
 // iterate over the notes of the melody:
 for (int thisNote = 0; thisNote < sizeof(melody)/sizeof(int); thisNote++) 
 {
   force = analogRead(fsr_pin);

   force_nor=map(force,695,0,0,99);
 

  forceCondition = 80;
  if (force_nor > forceCondition)
   {
     threshold_force = 1;
   }
 else
   {
     threshold_force = 0;
   }

 
  if ((threshold_force == 0))
   {
     thisNote=1000;
   }
  
   // to calculate the note duration, take one second divided by the note type.
   //e.g. half note = 1000 / 2
   
   int noteDuration = 1000/noteDurations[thisNote];
   tone(6, melody[thisNote],noteDuration);

   delay(noteDuration);
   
   noTone(6); // stop the tone playing
 }
}

Any help please? I’m really struggling with this program transistor and receiver program. I have attach the circuit for reference.

First: your forgot the code tags around your code.

I guess you mean transmitter by the word "transistor", so one Arduino sends information, the other receives it. But as far as I can see in your setup you don't have a connection between the two. How do you plan to transmit any information?

The easiest is a serial connection, you loose the debugging capability but as the rest of the code works already this shouldn't be that critical. So connect the two GNDs and the pins D0/D1 crossed and you can use the Serial object to send/receive data from the other Arduino.

Yes transistor and receiver. My setup is not complete as I not sure about it. I need to use radiometrix TX2-433-160-5V and RX2-433-160-5V to transmit the information. As for the program, can I know what do I have add in my current program to become transistor and make another file for receiver? Really appreciate your help.

A transistor is an electronic switching device and is not the same as a transmitter!

I need to use radiometrix TX2-433-160-5V and RX2-433-160-5V to transmit the information. As for the program, can I know what do I have add in my current program to become transistor and make another file for receiver?

That depends on the wiring. Post schematics of the planned setup with the transmission modules.

Please edit your post to add code tags.

radiometrix TX2-433-160-5V and RX2-433-160-5V

Best results with these radios will be achieved with the RadioHead library (or the older VirtualWire) library. There are simple library examples for send and receive, and there are many code examples available by searching this forum or the web.

EDIT: I suggest that you revise the title of your post to Transmitter and Receiver program

pylon:
A transistor is an electronic switching device and is not the same as a transmitter!

That depends on the wiring. Post schematics of the planned setup with the transmission modules.

Schematics at page 6 of PDF. I able to understand the roughly the setup. But programming I not sure what should I do with it.

I understand I need to add in #include <virtualwire.h>.

The void setup and void loop i am confused.

TX2RX2.pdf (740 KB)

cattledog: Best results with these radios will be achieved with the RadioHead library (or the older VirtualWire) library. There are simple library examples for send and receive, and there are many code examples available by searching this forum or the web.

EDIT: I suggest that you revise the title of your post to Transmitter and Receiver program

Hi

I have change as u suggested.

The void setup and void loop i am confused.

Please specify in detail what information needs to be sent from transmitter to the receiver.

You can develop the code between the two without the radios, by using the VW library and connecting the two arduino's together with wires.

You should also get the radios working with simple library example code and work out the details of the antennas and power supplys and possible range issues.

As previously asked--please revise your first post to place the code within code tags. See How to Use this Forum

cattledog:
Please specify in detail what information needs to be sent from transmitter to the receiver.

You can develop the code between the two without the radios, by using the VW library and connecting the two arduino’s together with wires.

You should also get the radios working with simple library example code and work out the details of the antennas and power supplys and possible range issues.

As previously asked–please revise your first post to place the code within code tags. See How to Use this Forum

Mind showing to me how to do? I’m just starting to learn this. Really facing a lot of problem getting the program to work.

As previously asked--please revise your first post to place the code within code tags. See How to Use this Forum

Mind showing to me how to do?

If you can not figure out how to read the instructions on how to use the forum and place your code in code tags, you will not be able to figure out how to use Virtual Wire and the radios.

I'm just starting to learn this.

Please specify in detail what information needs to be sent from transmitter to the receiver.

What does "starting to learn" have to do with being able to explain exactly what you want your program to do.

Do you just wish to send the values of ""Temp" and "Force" from one Arduino to another?

Did you look at the Virtual Wire example and can of send "Hello" from one Arduino to another? If you can't do this, you can't

show the same display on the transistor display with the receiver display.