Pedometer (Arduino 101)
Collect data such as step count, lost calories, temperature, etc.
Components and supplies
1
Jumper wires (generic)
1
9V battery (generic)
1
Rotary potentiometer (generic)
1
Standard LCD - 16x2 White on Blue
1
Arduino 101
1
DHT11 Temperature & Humidity Sensor (4 pins)
1
9V Battery Clip
Tools and machines
1
3D Printer (generic)
Apps and platforms
1
Arduino IDE
Project description
Code
Code
c_cpp
1// Frank, the living dead, made this code. 2// Chapecó, Brazil 3// This was my first project in 2017, for a science fair. 4// 2018 5 6 7// Thanks to: 8// Adafruit 9// Intel 10// Filipeflop 11// Keyes 12 13#include <DHT.h> 14#include <DHT_U.h> 15#include <LiquidCrystal.h> 16#include "CurieIMU.h" 17#include <SoftwareSerial.h> 18#include <Adafruit_Sensor.h> 19 20#define DHTPIN 8 21#define DHTTYPE DHT11 22 23LiquidCrystal lcd(12,10,5,4,3,2); 24 25int state=LOW; 26int lastState=LOW; 27const int ledPin = 13; 28boolean stepEventsEnabeled = true; 29long lastStepCount = 0; 30boolean blinkState = false; 31float comprimento_do_passo; 32float calories = 0; 33float peso = 57; 34float altura = 168; 35float calories_lost_per_km; 36float calories_burned; 37float distance; 38float passos_por_milha; 39float velocidade; 40char option; 41float t; 42 43DHT_Unified dht(DHTPIN, DHTTYPE); 44uint32_t delayMS; 45 46void setup() { 47 lcd.begin(16, 2); 48 dht.begin(); 49 50 comprimento_do_passo=0.30*altura; // Height in cm 51 calories_lost_per_km=(0.57*peso*1.6)/0.453; // Weight in kg 52 passos_por_milha = 160000.0/comprimento_do_passo; // 16000.0 CM = 16 KM 53 54 lcd.clear(); 55 lcd.setCursor(0, 0); 56 lcd.print("Pedometer"); 57 lcd.setCursor(0, 1); 58 lcd.print("Made by Frank :P"); 59 delay(3000); 60 61 // pinMode(13, OUTPUT); 62 CurieIMU.begin(); 63 CurieIMU.setStepDetectionMode(CURIE_IMU_STEP_MODE_NORMAL); 64 CurieIMU.setStepCountEnabled(true); 65 66 if (stepEventsEnabeled) { 67 // attach the eventCallback function as the 68 // step event handler: 69 CurieIMU.attachInterrupt(eventCallback); 70 CurieIMU.interrupts(CURIE_IMU_STEP); 71 } 72 73 74} 75 76static void updateStepCount() { 77 // Get the step count: 78 int stepCount = CurieIMU.getStepCount(); 79 80 // If the step count has changed, print it: 81 if (stepCount != lastStepCount) { 82 // Save the current count for comparison next check: 83 lastStepCount = stepCount; 84 } 85} 86 87static void eventCallback(void) { 88 if (CurieIMU.stepsDetected()) 89 updateStepCount(); 90} 91 92void loop() { 93 94 95 if (!stepEventsEnabeled) { 96 updateStepCount(); 97 } 98 99//__________________________________// 100 101 lcd.clear(); 102 lcd.setCursor(0, 0); 103 lcd.print("Steps: "); 104 lcd.setCursor(0, 1); 105 lcd.print(lastStepCount); 106 delay(4000); 107 108//__________________________________// 109 110calories_burned = lastStepCount*(lastStepCount/passos_por_milha); 111 112if (option=='c') { 113 114} 115 116 lcd.clear(); 117 lcd.setCursor(0, 0); 118 lcd.print("Calories B.: "); 119 lcd.setCursor(0, 1); 120 lcd.print(calories_burned); 121 lcd.print(" Kcal"); 122 delay(4000); 123 124//__________________________________// 125 126distance = (comprimento_do_passo*lastStepCount)/100; // Distance in meters 127 128if (option=='d') { 129 130} 131 132lcd.clear(); 133lcd.setCursor(0, 0); 134lcd.print("Distance: "); 135lcd.setCursor(0, 1); 136lcd.print(distance); 137lcd.print(" Meters"); 138delay(4000); 139 140//__________________________________// 141// CONECTION IN PIN 8 142 143 delay(delayMS); 144 sensors_event_t event; 145 dht.temperature().getEvent(&event); 146 if (isnan(event.temperature)) { 147 Serial.println("Error - Temp"); 148 } 149 else { 150 lcd.clear(); 151 lcd.setCursor(0, 0); 152 lcd.print("Temperature: "); 153 lcd.setCursor(0, 1); 154 lcd.print(event.temperature); 155 lcd.print(" C*"); 156 delay(3000); 157 } 158 159 dht.humidity().getEvent(&event); 160 if (isnan(event.relative_humidity)) { 161 Serial.println("Error - Humi"); 162 } 163 else { 164 lcd.clear(); 165 lcd.setCursor(0, 0); 166 lcd.print("Humidity: "); 167 lcd.setCursor(0, 1); 168 lcd.print(event.relative_humidity); 169 lcd.print("%"); 170 delay(3000); 171 } 172 173//__________________________________// 174 175 lastState=state; 176 digitalWrite(13, blinkState); 177 blinkState = !blinkState; 178 delay(300); 179
Downloadable files
Schmatic
The LCD is easy to set up.
Schmatic

Schmatic
The LCD is easy to set up.
Schmatic

Comments
Only logged in users can leave comments