Shape memory alloys (SMA) exhibit the shape memory effect (SME), allowing the alloy which is upon a cyclic thermal loading to return to its original shape after heating beyond the transformation temperature. Two-way SMAs deform during heating and cooling and are suitable for thermal energy harvesting applications. Also, piezoelectric materials (PM) can convert mechanical strain into electrical voltage or current. In this work, a thermal energy harvesting structure is introduced and analyzed. The structure is a composite cantilever beam, comprising two layers, i.e., one-way or two-way SMA and PM. The beam is subjected to different fluctuating temperature ranges, and then we obtain results about energy harvesting performance such as phase transformation strain and output voltage. After developing the nonlinear constitutive equations for one-way and two-way SMEs, the effect of pre-strain and two types of SMAs, i.e., one-way and two-way SMAs are compared with each other under a particular thermal loading. Moreover, the effect of the SMA thickness layer on the output voltage and power has been investigated. Regarding the results, we conclude that for larger pre-strains and maximum temperature of the cycle, greater piezoelectric power is induced. But for a small pre-strain (0.2%), no phase transformation and no output power are observed. Furthermore, it is concluded that in a thermal loading by using two-way SMAs, an electrical potential can be derived without any pre-strain, and increasing the thickness of SMA can rise output power remarkably.