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.
