Saturday, May 9, 2015

The New Bosch BME280 (Temp, Humidity, BMP)

Bosch has a new, very accurate all in one sensor chip that does Temperature, Humidity, and Barometric Pressure readings. It's called the BME280. Embedded Adventures has put that chip on a handy breakout board with signal conditioning (MOD-1022) and priced it fairly at $17. It's a 3v I2C unit, so to use it with a Arduino UNO, you will need a bi-directional level shifter, which they also have as the MOD-1003S for an additional $10.

This is the most accurate unit I have found, and is very easy to use. The library and sample code are available on the MOD-1022 page above, and the MOD-1003S level shifter requires no code to use.

There are only 4 wires to connect from the MOD-1022 to the MOD-1003S (VDD -> +3.3v, SCL -> B2), SDA -> B1, Gnd), and 4 wires from the MOD-1003S to the Arduino (+5v, SCL(B2 ->A5), SDA(B1->A4), Gnd). Download and install the library, and upload the example sketch included with the library, and you are on your way (in metric). For US measurements, you will have to convert Celsius to Fahrenheit, and hPa to InHg.

The example sketch communicates with serial defaulting to 115200, so make sure your serial monitor is set accordingly.

See schematic after the code.



Copyright (c) 2015, Embedded Adventures
All rights reserved.

Contact us at source [at]

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

- Redistributions of source code must retain the above copyright notice,
  this list of conditions and the following disclaimer.

- Redistributions in binary form must reproduce the above copyright
  notice, this list of conditions and the following disclaimer in the
  documentation and/or other materials provided with the distribution.

- Neither the name of Embedded Adventures nor the names of its contributors
  may be used to endorse or promote products derived from this software
  without specific prior written permission.


// BME280 MOD-1022 weather multi-sensor Arduino demo
// Written originally by Embedded Adventures

#include <BME280_MOD-1022.h>

#include <Wire.h>

// Arduino needs this to pring pretty numbers

void printFormattedFloat(float x, uint8_t precision) {
char buffer[10];

  dtostrf(x, 7, precision, buffer);


// print out the measurements

void printCompensatedMeasurements(void) {

float temp, humidity,  pressure, pressureMoreAccurate;
double tempMostAccurate, humidityMostAccurate, pressureMostAccurate;
char buffer[80];

  temp      = BME280.getTemperature();
  humidity  = BME280.getHumidity();
  pressure  = BME280.getPressure();
  pressureMoreAccurate = BME280.getPressureMoreAccurate();  // t_fine already calculated from getTemperaure() above
  tempMostAccurate     = BME280.getTemperatureMostAccurate();
  humidityMostAccurate = BME280.getHumidityMostAccurate();
  pressureMostAccurate = BME280.getPressureMostAccurate();
  Serial.println("                Good  Better    Best");
  Serial.print("Temperature  ");
  printFormattedFloat(temp, 2);
  Serial.print("         ");
  printFormattedFloat(tempMostAccurate, 2);
  Serial.print("Humidity     ");
  printFormattedFloat(humidity, 2);
  Serial.print("         ");
  printFormattedFloat(humidityMostAccurate, 2);

  Serial.print("Pressure     ");
  printFormattedFloat(pressure, 2);
  Serial.print(" ");
  printFormattedFloat(pressureMoreAccurate, 2);
  Serial.print(" ");
  printFormattedFloat(pressureMostAccurate, 2);

// setup wire and serial

void setup()

// main loop

void loop()

  uint8_t chipID;
  Serial.println("Welcome to the BME280 MOD-1022 weather multi-sensor test sketch!");
  Serial.println("Embedded Adventures (");
  chipID = BME280.readChipId();
  // find the chip ID out just for fun
  Serial.print("ChipID = 0x");
  Serial.print(chipID, HEX);
  // need to read the NVM compensation parameters
  // Need to turn on 1x oversampling, default is os_skipped, which means it doesn't measure anything
  BME280.writeOversamplingPressure(os1x);  // 1x over sampling (ie, just one sample)
  // example of a forced sample.  After taking the measurement the chip goes back to sleep
  while (BME280.isMeasuring()) {
  // read out the data - must do this before calling the getxxxxx routines
  Serial.println(BME280.getTemperature());  // must get temp first
  Serial.println(BME280.getPressureMoreAccurate());  // use int64 calculcations
  Serial.println(BME280.getTemperatureMostAccurate());  // use double calculations
  Serial.println(BME280.getHumidityMostAccurate()); // use double calculations
  Serial.println(BME280.getPressureMostAccurate()); // use double calculations
  // Example for "indoor navigation"
  // We'll switch into normal mode for regular automatic samples
  BME280.writeStandbyTime(tsb_0p5ms);        // tsb = 0.5ms
  BME280.writeFilterCoefficient(fc_16);      // IIR Filter coefficient 16
  BME280.writeOversamplingPressure(os16x);    // pressure x16
  BME280.writeOversamplingTemperature(os2x);  // temperature x2
  BME280.writeOversamplingHumidity(os1x);     // humidity x1
  while (1) {
    while (BME280.isMeasuring()) {

    // read out the data - must do this before calling the getxxxxx routines
    delay(5000); // do this every 5 seconds

Monday, May 4, 2015

Remote Control Mood Lamp

I love RGB LED's. One little module can produce a wide spectrum of colors just by varying the signal on the red, green and blue pins. I also love my TV remote, as I am a bit of a couch potato. What if I could change the mood of the room, with my TV remote?

I took an arduino, connected a RGB LED module that has the three dropping resistors on board, and connected a InfraRed (IR) receiver out of an old VCR. Radio shack sells these for about 80 cents. You could use three separate LED's and 220 Ohm resistors, but the effect would not be the same. You could also get a RGB LED, and add the three resistors to it.

I went a step further, and connected a LED to the output of the receiver chip so I would get a visual confirmation that the receiver saw a signal from the remote. That part isn't necessary, so I left it off the schematic. If you want to implement, connect a 220 ohm resistor to the IR module signal pin. Connect the other end of the resistor to the short leg of an LED (color is your choice). Connect the long end of the LED to Arduino +5. The receiver outputs a LOW when it sees a IR signal.

I cut a small hole in a ping pong ball and placed it over the RGB LED (tape holds the module in place) to diffuse the light and make the whole ball glow with color.

I'm not detecting actual codes, just an IR signal, so this project will work with any remote you have laying around, and any button on the remote. It just cycles to the next color.

All 3 LED pins are connected to PWM pins, so you can add additional case statements, and change the pwm values with analogWrite to the pins, to create new and additional colors.


int ledcolor = 0;
int red = 9; //this sets the red led pin
int green = 10; //this sets the green led pin
int blue = 11; //this sets the blue led pin

void setup() {
  // put your setup code here, to run once:
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(blue, OUTPUT);

void loop() {
  if (ledcolor > 6){
  // put your main code here, to run repeatedly:
bool triggered = digitalRead(12);
if (triggered == LOW){

switch (ledcolor) {
case 0: //if ledcolor equals 0 then the led will turn red
digitalWrite(red, LOW);
digitalWrite(green, LOW);
digitalWrite(blue, LOW);
analogWrite(red, 204);

case 1: //if ledcolor equals 1 then the led will turn green
digitalWrite(red, LOW);
digitalWrite(green, HIGH);

case 2: //if ledcolor equals 2 then the led will turn blue
digitalWrite(green, LOW);
digitalWrite(blue, HIGH);

case 3: //if ledcolor equals 3 then the led will turn yellow
digitalWrite(blue, LOW);
analogWrite(red, 160);
digitalWrite(green, HIGH);

case 4: //if ledcolor equals 4 then the led will turn cyan
digitalWrite(red, LOW);
digitalWrite(green, LOW);
analogWrite(red, 168);
digitalWrite(blue, HIGH);

case 5: //if ledcolor equals 5 then the led will turn magenta
digitalWrite(red, LOW);
digitalWrite(blue, LOW);
digitalWrite(green, HIGH);
digitalWrite(blue, HIGH);

case 6: //if ledcolor equals 6 then the led will turn white
digitalWrite(green, LOW);
digitalWrite(blue, LOW);
analogWrite(red, 100);
digitalWrite(green, HIGH);
digitalWrite(blue, HIGH);


Related Posts Plugin for WordPress, Blogger...