Go Down

Topic: Help with a Computer Technology Project (Read 386 times) previous topic - next topic

Jan 11, 2019, 11:40 pm Last Edit: Jan 12, 2019, 12:11 am by RyaanAli
So I have been assigned a summative for my grade 10 computer technology course to design an arduino gadget. My idea is a clock essentially which connects via Bluetooth to the users phone. It uses a DHT11, LCD, HC-05, Arduino Uno Mega328. How its supposed to work is it cycles through several screens on the LCD. One displays time, the other displays the temperature of the room, then the humidity of the room. If the phone receives a call an LED lights up and the LCD displays call incoming. There is also a button for a speed dial feature. I am really new to arduino and this is an ambitious project. the reason I did not use a RTC for the time is because we do not have access to them. The Bluetooth connects to an App I have designed on MIT App Inventor 2. Below I will attach a schematic diagram, code for the arduino, and code for the app. Please note that I accidentally switched the TX and RX wires for the Bluetooth module and fixed it later when testing.

The issues that have come up are that the button keeps showing its state as HIGH resulting in the display only showing the speed dial function, and when the Bluetooth is connected to the app, it is not receiving the time so that the arduino can display it. I discussed this with my teacher and she advised creating a post here. All help is welcome.

*(Edit) I forgot to mention the code for the speed dial was removed from the app temporarily when testing to stop possible accidental calls*



Code: [Select]
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <dht.h>//Libraries required for the code

dht DHT;//Temperature and Humidity Sensor setup
LiquidCrystal_I2C lcd(0x27, 16, 2);//LCD Display set up

const int DHT_PIN = 2; //Temperature and Humidity Sensor Input
const int Caller_Button = 3;//Caller Button Input
const int Caller_LED = 4; // Caller LED output

void setup() {
  pinMode(DHT_PIN, INPUT);
  pinMode(Caller_Button, INPUT);
  pinMode(Caller_LED, OUTPUT);
  digitalWrite(DHT_PIN, LOW);
  digitalWrite(Caller_Button, LOW); 
  Serial.begin(9600);
  lcd.begin(16,2);
  lcd.init();
  lcd.backlight();
  //Prepares the code to run and initializes everything including pin modes and serial as well as LCD
  }
 
void loop() {
  int Caller_Button_State;
  Caller_Button_State = digitalRead(Caller_Button);
  if (Serial.available())
  {
  CallerDisplay();
  }
  else if(Caller_Button_State = HIGH)
  {
   SpeedDial();
  }
  else
  {
  WelcomeScreen();
  TimeDisplay();
  TemperatureDisplay();
  HumidityDisplay();
  }
}

void TimeDisplay() //Display for time
{
    Serial.write(1);
    String Time = Serial.readString();
    lcd.setCursor(0,0);
    lcd.print("The Time Is");
    lcd.setCursor(0,1);
    lcd.print(Time);
    delay(5000);
    lcd.clear();
}

void TemperatureDisplay() //Display for temperature
{
  int chk = DHT.read11(DHT_PIN);
  lcd.setCursor(0,0);
  lcd.print("Temperature:");
  lcd.setCursor(0,1);
  lcd.print(DHT.temperature);
  lcd.print((char)223);
  lcd.print("C");
  delay(5000); 
  lcd.clear(); //Clears Screen
}

void HumidityDisplay() //Display for humidity
{
   int chk = DHT.read11(DHT_PIN);
   lcd.setCursor(0,0);
   lcd.print("Humidity:");
   lcd.setCursor(0,1);
   lcd.print(DHT.humidity);
   lcd.print("%");
   delay(5000);
   lcd.clear(); //Clears screen
}

void WelcomeScreen() //Welcomes User
{
   lcd.setCursor(0,0);
   lcd.print("Hello Ryaan");//The string in this line can be changed to any welcome statement
   delay(5000);
   lcd.clear();
}

void CallerDisplay()//Display for when a call is detected
{
   int CMD = Serial.read();
   if (CMD == 1)
   {
    digitalWrite(Caller_LED, HIGH);
    lcd.setCursor(0,0);
    lcd.print("Call Incoming");
   delay(20000);
   CMD = 0;
   lcd.clear();
   }
}

void SpeedDial()//Runs Speed Dial Function
{
    Serial.write(2);
    lcd.setCursor(0,0);
    lcd.print("Calling");
    lcd.setCursor(0,1);
    lcd.print("Amtoj");//This name can be changed to whatever number and the number being called can be changed in the code of the App
}

Robin2

Please display your image(s) in your post so we can see it(them) without downloading it(them). See this  Simple Image Guide

And, as your program is short, please show it in your Post. Please use the code button </>
Code: [Select]
so it looks like this. It makes it much easier for people to help you.  See How to use the Forum

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Paul__B

I discussed this with my teacher and she advised creating a post here.
Wow!

I can only say that is an "interesting" approach to teaching!

Wow!

I can only say that is an "interesting" approach to teaching!
She says she would try and take a look Monday but her knowledge of arduino is also limited.

pert

When you are not pushing the caller button, pin 3 is floating. A floating input pin can be in any random state and switch from one state to another. In order to ensure that a pin is always in a known state, we use either a pull-up or a pull-down resistor. Since your button is connected to ground, you would want to use a pull-up resistor on pin 3 so that you will be certain that the pin will always be HIGH when the button is not pressed. You can use an external resistor if you like, but the Uno's ATmega328P also has internal pull-up resistors, which can be turned on from your sketch by setting the pin mode to INPUT_PULLUP:
Code: [Select]
pinMode(Caller_Button, INPUT_PULLUP);

More information:


Code: [Select]
 Caller_Button_State = digitalRead(Caller_Button);
  if (Serial.available())
  {
  CallerDisplay();
  }
  else if(Caller_Button_State = HIGH)
  {

A couple problems here. First, your button is connected to ground, so Caller_Button will be LOW when the button is pressed.

Also, you need to study the difference between the assignment operator (=) and the comparison operator (==).

I have an external 220ohm resistor hooked up already. I see the mistake I made with "=" and "==". As for it being LOW when pressed, I did not know that an will make the change needed.


Paul__B

I have an external 220ohm resistor hooked up already.
Sounds like a kit!

A 4k7 would probably be more appropriate.


pert

I have an external 220ohm resistor hooked up already.
That resistor is not providing a pull-down on the Uno's pin. It is only acting to limit current when the button is pressed. If you want to see how to to correctly connect an external pull-down resistor, study this tutorial:
https://www.arduino.cc/en/Tutorial/Button



If you change your circuit to use an external pull-down resistor and connect the button between pin 3 and 5 V, then your current code would be correct (pin is HIGH when the button is pressed). However, it's convenient to use the internal pull-up in order to simplify the circuit by eliminating the need for an external resistor.

pert

The tutorial we followed originally when learning about the parts was this:



We replaced 330 Ohms with 220 Ohms because of insufficient supplies but it caused no major issues. All out equipment is from a kit from china. After having some issues trying to get my arduino to be an HID keyboard I discovered that they were knockoffs from china lacking a second Mega16 which was changed for a CH340.
That link is broken. Here's the correct one:
https://learn.sparkfun.com/tutorials/sik-experiment-guide-for-arduino---v33/experiment-5-push-buttons
The 330 ohm resistor in that tutorial is used to limit current to the LED. The tutorial uses 10K ohm resistors for the external pull-ups on the buttons. Note that the wiring of the buttons in your schematic does not match the Fritzing diagrams in the tutorial.

#11
Jan 12, 2019, 12:42 am Last Edit: Jan 12, 2019, 12:44 am by RyaanAli
I have changed the code to use the internal pull up rather then the pull down. Ill edit my schematic design as well. Sometimes its the stupidest mistakes I make, last time I forgot to power the buttons. Would I need to remove the resistor with the pull up or simply keep it and remove the pull up? Thanks for the help. Have any ideas for the Time Display to get the time through Bluetooth?

This is the new code
Code: [Select]
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <dht.h>//Libraries required for the code

dht DHT;//Temperature and Humidity Sensor setup
LiquidCrystal_I2C lcd(0x27, 16, 2);//LCD Display set up

const int DHT_PIN = 2; //Temperature and Humidity Sensor Input
const int Caller_Button = 3;//Caller Button Input
const int Caller_LED = 4; // Caller LED output

void setup() {
  pinMode(DHT_PIN, INPUT);
  pinMode(Caller_Button, INPUT_PULLUP);
  pinMode(Caller_LED, OUTPUT);
  digitalWrite(DHT_PIN, LOW);
  digitalWrite(Caller_Button, HIGH); 
  Serial.begin(9600);
  lcd.begin(16,2);
  lcd.init();
  lcd.backlight();
  //Prepares the code to run and initializes everything including pin modes and serial as well as LCD
  }
 
void loop() {
  int Caller_Button_State;
  Caller_Button_State = digitalRead(Caller_Button);
  if (Serial.available())
  {
  CallerDisplay();
  }
  else if(Caller_Button_State == LOW)
  {
   SpeedDial();
  }
  else
  {
  WelcomeScreen();
  TimeDisplay();
  TemperatureDisplay();
  HumidityDisplay();
  }
}

void TimeDisplay() //Display for time
{
    Serial.write(1);
    String Time = Serial.readString();
    lcd.setCursor(0,0);
    lcd.print("The Time Is");
    lcd.setCursor(0,1);
    lcd.print(Time);
    delay(5000);
    lcd.clear();
}

void TemperatureDisplay() //Display for temperature
{
  int chk = DHT.read11(DHT_PIN);
  lcd.setCursor(0,0);
  lcd.print("Temperature:");
  lcd.setCursor(0,1);
  lcd.print(DHT.temperature);
  lcd.print((char)223);
  lcd.print("C");
  delay(5000); 
  lcd.clear(); //Clears Screen
}

void HumidityDisplay() //Display for humidity
{
   int chk = DHT.read11(DHT_PIN);
   lcd.setCursor(0,0);
   lcd.print("Humidity:");
   lcd.setCursor(0,1);
   lcd.print(DHT.humidity);
   lcd.print("%");
   delay(5000);
   lcd.clear(); //Clears screen
}

void WelcomeScreen() //Welcomes User
{
   lcd.setCursor(0,0);
   lcd.print("Hello Ryaan");//The string in this line can be changed to any welcome statement
   delay(5000);
   lcd.clear();
}

void CallerDisplay()//Display for when a call is detected
{
   int CMD = Serial.read();
   if (CMD == 1)
   {
    digitalWrite(Caller_LED, HIGH);
    lcd.setCursor(0,0);
    lcd.print("Call Incoming");
   delay(20000);
   CMD = 0;
   lcd.clear();
   }
}

void SpeedDial()//Runs Speed Dial Function
{
    Serial.write(2);
    lcd.setCursor(0,0);
    lcd.print("Calling");
    lcd.setCursor(0,1);
    lcd.print("Amtoj");//This name can be changed to whatever number and the number being called can be changed in the code of the App
}


pert

#13
Jan 12, 2019, 01:24 am Last Edit: Jan 12, 2019, 01:24 am by pert
From the "How to use this forum - please read" sticky at the top of every forum section:
http://forum.arduino.cc/index.php/topic,148850.msg1118325.html#post_etiquette
Quote
Don't bump!

Don't bump your thread after an hour. Because of the different time-zones the person who knows the answer may be asleep, or away for the day. Maybe after a couple of days.

If your question didn't get an answer, honestly review it to see if you posted enough information to help people answer you. Did you even ask a question?
You didn't even wait an hour!

Apologies, I'm really new to this and the stress of this summative is getting to me.

Go Up